<template>
  <div>
    <h1>评审报告生成</h1>
    <el-card>
      <!-- <ReviewReport component-name="邀请招标" />
      <CompetitiveNegotiation component-name="竞争性磋商" />
      <Negotiation component-name="谈判" />
      <CompanyTemplate /> 
      <RejectTemplate />
      -->
      <div v-if="currentComponent" class="mb-4">
        <component :is="currentComponent" :component-name="currentType" />
      </div>
      <div v-else class="flex items-center justify-center">
        <el-empty description="评标未结束，无法生成评审报告" />
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
// 废标模板
import RejectTemplate from './components/RejectTemplate.vue'
// 邀请招标
import ReviewReport from './components/ReviewReport.vue'
// 竞争性磋商
import CompetitiveNegotiation from './components/CompetitiveNegotiation.vue'
// 谈判
import Negotiation from './components/Negotiation.vue'
// 公司模板
import CompanyTemplate from './components/CompanyTemplate.vue'
import { getProjectStatus } from '@/api/review-report-generation'
// CG
const COMPONENTS_MAP_CG = {
  邀请招标: markRaw(ReviewReport),
  '公开招标（500万元以上）': markRaw(ReviewReport),
  '公开招标（500万元以下）': markRaw(ReviewReport),
  竞争性磋商: markRaw(CompetitiveNegotiation),
  谈判: markRaw(Negotiation),
  竞争性谈判: markRaw(Negotiation)
}
const currentType = ref<string>('')
const currentComponent = ref<any>(null)
const getComponent = async () => {
  const projectInfo = useProjectInfoStore().projectInfo
  const { bidType, projectNumber } = projectInfo
  const { status, supplierCount }: any = await getProjectStatus()
  if (status === '评标结束') {
    currentType.value = bidType
    // 小于3家 直接显示废标模板模板
    if (Number(supplierCount) < 3) {
      currentComponent.value = markRaw(RejectTemplate)
      return
    }
    if (projectNumber?.startsWith('CG')) {
      currentComponent.value = COMPONENTS_MAP_CG[bidType]
      return
    }
    if (projectNumber?.startsWith('GC')) {
      currentComponent.value = markRaw(CompanyTemplate) // GC 只有一个模板
      return
    }
  }
}
onMounted(() => {
  getComponent()
})
</script>

<style lang="scss" scoped>
.table-report {
  padding: 20px 40px;
}
</style>
